﻿using System;
using Playground.Scratches;

namespace Playground.Execute
{
    /// <summary>
    /// Executes various programs
    /// </summary>
    public class Commands
    {
        /// <summary>
        /// Entry point of all programs
        /// </summary>
        public static void Main()
        {
            Console.WriteLine("*** List of Programs ***");
            Console.WriteLine("Option 1: Lottery Prediction Numbers");
            Console.WriteLine("Option 2: Dynamic Initalization");
            Console.WriteLine("Option 3: String Formatting");
            Console.WriteLine("Option 4: Switch Statement");
            Console.WriteLine("Option 5: Multi Loop Control");
            Console.WriteLine("Option 6: Vehicle Demo");
            Console.WriteLine("Option 7: Two Vehicles Demo");
            Console.WriteLine("Option 8: Execute Fuel Comp");
            Console.WriteLine("Option 9: Object Destruction Demo");
            Console.WriteLine("Option 10: MultiDimensional Array");
            Console.WriteLine("Option 11: TernaryOperator(?)");
            Console.WriteLine("Option 12: Block Object Testing");
            Console.WriteLine();
            ExeDashboad(ReadArgument());
        }

        /// <summary>
        /// Reads the argument and verifies that the arg is valid
        /// </summary>
        /// <returns></returns>
        private static int ReadArgument()
        {
            //just to make it look better
            Console.Write("> ");
            var option = 0;

            //read a line
            string arg = Console.ReadLine();

            if (arg != null)
            {
                option = int.Parse(arg);
            }
            return option;
        }

        /// <summary>
        /// Execute programs using the arg as a param
        /// </summary>
        /// <param name="op"></param>
        private static void ExeDashboad(int op)
        {
            switch (op)
            {
                case 1:
                    LotteryPrediction.Prediction.Execute();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 2:
                    Samples.DynamicInitialization();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 3:
                    Samples.StringFormatting();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 4:
                    Samples.SwitchStatements();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 5:
                    Samples.MultiLoopControl();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 6:
                    ExecuteVehicleDemo();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 7:
                    ExecuteTwoVehicleDemo();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 8:
                    ExecuteCompFuel();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 9:
                    Samples.BubbleSort();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 10:
                    Samples.MultiDimensionalArrays();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 11:
                    Samples.TernaryOperator();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                case 12:
                    PassOb.ExecuteBlock();
                    Console.Write("[Message] Press any key to Exit.");
                    Console.ReadLine();
                    break;
                default:
                    Console.WriteLine("[Error] Invalid option. Press any key to Exit.");
                    Console.ReadLine();
                    Environment.Exit(1);
                    break;
            }
        }

        private static void ExecuteVehicleDemo()
        {
            //using the object initializer
            var minivan = new Vehicle(7, 16, 21);
            // compute the range assuming a full tank of gas
            int range = minivan.Fuelcap * minivan.Mpg;
            Console.WriteLine("Minivan can carry " + minivan.Passangers + " with a range of " + range);
        }

        private static void ExecuteTwoVehicleDemo()
        {
            //object initializer
            var minivan = new Vehicle(7, 16, 21);
            var sportscar = new Vehicle(2, 14, 2);

            minivan.Range();
            sportscar.Range();
        }

        private static void ExecuteCompFuel()
        {
            var minivan = new Vehicle(7, 16, 21);
            var sportscar = new Vehicle(2, 14, 12);
            const int dist = 252;

            double gallons = minivan.FuelNeeded(dist);
            Console.WriteLine("To go " + dist + " miles minvan needs " + gallons + " gallons of fuel");

            gallons = sportscar.FuelNeeded(dist);
            Console.WriteLine("To go " + dist + " miles sportscar needs " + gallons + " gallons of fuel");
        }

        private static void ObjectDestructionDemo()
        {
            const int objCount = 10000;
            var ob = new ObjectDesrtuctor(0);

            /* generate a large number of objects. 
             * At some point, garbage collection will occur.
             */

            for (int count = 1; count < objCount; count++)
            {
                ob.Generator(count);
            }
        }

    }
}
